package com.team.controller;


import com.team.commons.dto.ProductDetailsGatherDto;
import com.team.commons.vo.ProductDetailsVo;
import com.team.commons.vo.ProductListVo;
import com.team.commons.vo.ProductVo;
import com.team.result.ResponseEntity;
import com.team.service.ProductService;
import com.team.service.ProductionEditorService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/product")
public class ProductController {

    @Resource
    ProductService productService;
    @Resource
    ProductionEditorService productionEditorService;

    /**
     * 列表查询
     * @param current 当前页数
     * @param state 产品状态
     * @param type  产品类型
     * @return
     */
    @PostMapping("/list")
    public ResponseEntity<ProductListVo> selectList(@RequestParam(value = "current",defaultValue = "1") Integer current,
                                              @RequestParam(value = "state",defaultValue = "1")Integer state,
                                              @RequestParam(value = "type",defaultValue = "团建旅游")String type){
        return ResponseEntity.success(productService.selectList(current,state,type));
    }

    /**
     * 关键字查询查询
     * @param current 当前页数
     * @param key  模糊查询关键字
     * @return
     */
    @PostMapping("/listKey")
    public ResponseEntity<List<ProductVo>> selectKey(@RequestParam(value = "current",defaultValue = "1")Integer current,
                                                     @RequestParam(value = "key",defaultValue = "")String key){
        return ResponseEntity.success(productService.selectListKey(current,key));
    }

    /**
     * 查询产品编辑界面
     * @param productId
     * @return
     */
    @PostMapping("/details")
    public ResponseEntity<ProductDetailsGatherDto> selectProductDetailsGather(@RequestParam(value = "productId") Long productId){
        return ResponseEntity.success(productionEditorService.selectProductionEditor(productId));
    }

    /**
     * 更新产品编辑界面
     * @param productDetailsGatherDto
     * @return
     */
    @PostMapping("/productUpDate")
    public ResponseEntity<Integer> updateProductDetailsGather(@RequestParam(value ="productDate") ProductDetailsGatherDto productDetailsGatherDto){
        return ResponseEntity.success(productionEditorService.updateProductionEditor(productDetailsGatherDto));
    }

    /**
     * 更新产品当前状态 0仓库 1上架 2下架 3草稿 。。。
     * @param ProductIdList
     * @param state
     * @return
     */
    @PostMapping("/updateProductState")
    public ResponseEntity<Integer> updateStateProduct(@RequestParam(value = "ProductIdList") List<Long> ProductIdList,
                                                      @RequestParam(value = "state") Integer state){
        return ResponseEntity.success(productService.updateStateProduct(ProductIdList,state));
    }


}
